﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLKS.ServiceReferenceQLKS;
namespace QLKS
{
    public partial class FrmCheckLogin : Form
    {
        public NHANVIEN nhanvien;
        
        public FrmCheckLogin()
        {
            InitializeComponent();
        }
        private void CheckLogin()
        {
            NHANVIEN[] outnv;
            NHANVIEN modelnhanvien = new NHANVIEN();
            if (txtmanv.Text == null)
            {
                MessageBox.Show("Đề nghị nhập mã nhân viên", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtmanv.Focus();
                return;
            }
            if (txtmk.Text == null)
            {
                MessageBox.Show("Đề nghị nhập mật khẩu", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtmk.Focus();
                return;
            }
            modelnhanvien.MatKhau = txtmk.Text;
            modelnhanvien.MSNV = txtmanv.Text;
            var client = new ServiceQLKSClient();
            var error = client.doparserPerson(out outnv, OPTCodeQLKS.OPTCode_NHANVIEN_CHECKLOGIN, modelnhanvien);
            if (error == ErrorCodeQLKS.CODE_NHANVIEN_CHECKLOGIN_SUCCESS)
            {
                FrmHeThong frm = new FrmHeThong();
                frm.Show();
                nhanvien = modelnhanvien;
                this.Hide();
            }
            try
            {
                if (client.State != System.ServiceModel.CommunicationState.Faulted)
                {
                    client.Close();
                }
            }
            catch (Exception ex)
            {
                client.Abort();
            }
        }

        private void btndangnhap_Click(object sender, EventArgs e)
        {
            CheckLogin();
        }

        private void btnthoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
